function LockTableHead(tableId)
{
    var t = document.getElementById(tableId);
    var ttrs = t.getElementsByTagName('tr');
    var top, left;
    var nt;

    this.ResizeTableHead = _ResizeTableHead;

    if (t)
    {
        nt = t.cloneNode(true);
        for(var i = nt.rows.length - 1;  i > 0; i--)
        {
            nt.deleteRow(i);
        }
        
        document.body.appendChild(nt);

        _ResizeTableHead();
        
        document.body.onscroll = _ScrollHead;
        
        document.body.onresize = _ResizeTableHead;
    }

    function _ScrollHead()
    {
        window.status = top;
        if (document.body.scrollTop >= top)
        {
            nt.style.top = document.body.scrollTop;
        }
        else
        {
            nt.style.top = top;
        }
    }

    function _ResizeTableHead()
    {
        nt.style.width = t.offsetWidth;
        nt.style.position = 'absolute';
        nt.style.height = "";

        top = t.offsetTop;
        left = t.offsetLeft;

        var t2 = t;
        while(t2.offsetParent)
        {
            t2 = t2.offsetParent;
            top += t2.offsetTop;
            left += t2.offsetLeft;
        }
        nt.style.left = left;
        _ScrollHead();
        nt.style.zIndex = 100;
        //
        var nttrs = nt.getElementsByTagName('tr');

        for(var i = 0; i < nttrs[0].childNodes.length; i++)
        {
            nttrs[0].childNodes[i].style.width = ttrs[0].childNodes[i].offsetWidth;
            nttrs[0].childNodes[i].style.height = ttrs[0].childNodes[i].offsetHeight;
        }
    }
}